<template>
  <div class="container">
    <div class="login_box">
      <div class="title_box" style="margin-bottom: 20px">
        <span class="title_text">欢迎登录</span>
        <span class="tip_text">紫鸟浏览器</span>
      </div>
      <div class="title_box">
        <span class="select_text">密码登录</span>
      </div>
      <div class="form_box">
        <el-form
          label-position="right"
          label-width="100px"
          :model="loginForm"
          :rules="rules"
        >
          <el-form-item label-width="0px" prop="username">
            <el-input
              v-model="loginForm.username"
              placeholder="请输入用户名"
              size="large"
            >
              <template #prefix>
                <el-icon class="el-input__icon"><User /></el-icon>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item label-width="0px" prop="password">
            <el-input
              type="password"
              v-model="loginForm.password"
              placeholder="请输入密码"
              size="large"
            >
              <template #prefix>
                <el-icon class="el-input__icon"><Lock /></el-icon>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item label-width="0px">
            <button type="button" @click="toLogin">
              <span class="span-mother">
                <span>登</span>
                <span>陆</span>
              </span>
              <span class="span-mother2">
                <span>登</span>
                <span>陆</span>
              </span>
            </button>
          </el-form-item>
        </el-form>
      </div>
      <div class="right_text">
        <span class="tip_text" style="cursor: pointer">忘记密码</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, defineOptions } from "vue";
import { User, Lock } from "@element-plus/icons-vue";
import * as userApi from "../../api/user/user.js";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";

defineOptions({ name: "Login" });

// 响应式变量
const loginForm = ref({
  username: "",
  password: "",
});

const rules = {
  username: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
  password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
};
const router = new useRouter();

// 事件处理函数
const toLogin = async () => {
  // const res = await userApi.login(loginForm.value)
  // const {code ,msg ,data} = res
  // if(code !== '200'){
  //   ElMessage.error(msg)
  //   return
  // }
  // localStorage.setItem('token',res)
  router.push({
    name: "index",
  });
};
</script>

<style lang="less" scoped>
.container {
  background-image: url("https://p0.itc.cn/q_70/images01/20220531/02fd6779836a4a74b9899a36894fe40a.jpeg");
  background-size: cover;
  background-repeat: no-repeat;
}
.login_box {
  width: 20%;
  height: 45%;
  background-color: #ffffff;
  border-radius: 5px;
  margin: 10% 15%;
}
/* From Uiverse.io by KINGFRESS */
button {
  font-weight: bold;
  color: white;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
  height: 42.66px;
  border: none;
  background-color: var(--primary-color);
  display: flex;
  justify-content: center;
  align-items: center;
}

button .span-mother {
  display: flex;
  overflow: hidden;
}

button:hover .span-mother {
  position: absolute;
}

button:hover .span-mother span {
  transform: translateY(1.2em);
}

button .span-mother span:nth-child(1) {
  transition: 0.2s;
}

button .span-mother span:nth-child(2) {
  transition: 0.3s;
}

button .span-mother span:nth-child(3) {
  transition: 0.4s;
}

button .span-mother span:nth-child(4) {
  transition: 0.5s;
}

button .span-mother span:nth-child(5) {
  transition: 0.6s;
}

button .span-mother span:nth-child(6) {
  transition: 0.7s;
}

button .span-mother2 {
  display: flex;
  position: absolute;
  overflow: hidden;
}

button .span-mother2 span {
  transform: translateY(-1.2em);
}

button:hover .span-mother2 span {
  transform: translateY(0);
}

button .span-mother2 span {
  transition: 0.2s;
}

button .span-mother2 span:nth-child(2) {
  transition: 0.3s;
}

button .span-mother2 span:nth-child(3) {
  transition: 0.4s;
}

button .span-mother2 span:nth-child(4) {
  transition: 0.5s;
}

button .span-mother2 span:nth-child(5) {
  transition: 0.6s;
}

button .span-mother2 span:nth-child(6) {
  transition: 0.7s;
}
.right_text {
  display: flex;
  justify-content: flex-end;
  width: 90%;
}
</style>
